package io.renren.entity;

/**
 * 列的属性
 * 
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2016年12月20日 上午12:01:45
 */
public class ColumnEntity {
	//列名
	private String columnName;
	//列名类型
	private String dataType;
	//长度限制
	private Integer dataLength;
	//小数位
	private Integer dataScale;
	//是否为空
	private String nullable;
	//列名备注
	private String comments;

	//属性名称(第一个字母大写)，如：user_name => UserName
	private String attrName;
	//属性名称(第一个字母小写)，如：user_name => userName
	private String attrname;
	//属性类型
	private String attrType;
	//auto_increment
	private String extra;

	private boolean isNumber;

	private Long maxValue;

	private Boolean isGmtField;

	public String getColumnName() {
		return columnName;
	}

	public void setColumnName(String columnName) {
		this.columnName = columnName;
	}

	public String getDataType() {
		return dataType;
	}

	public void setDataType(String dataType) {
		this.dataType = dataType;
	}

	public String getComments() {
		return comments;
	}

	public void setComments(String comments) {
		this.comments = comments;
	}

	public String getAttrname() {
		return attrname;
	}

	public void setAttrname(String attrname) {
		this.attrname = attrname;
	}

	public String getAttrName() {
		return attrName;
	}

	public void setAttrName(String attrName) {
		this.attrName = attrName;
	}

	public String getAttrType() {
		return attrType;
	}

	public void setAttrType(String attrType) {
		this.attrType = attrType;
	}

	public String getExtra() {
		return extra;
	}

	public void setExtra(String extra) {
		this.extra = extra;
	}

	public Integer getDataLength() {
		return dataLength;
	}

	public void setDataLength(Integer dataLength) {
		this.dataLength = dataLength;
	}

	public Integer getDataScale() {
		return dataScale;
	}

	public void setDataScale(Integer dataScale) {
		this.dataScale = dataScale;
	}

	public String getNullable() {
		return nullable;
	}

	public void setNullable(String nullable) {
		this.nullable = nullable;
	}

	public boolean getIsNumber() {

		return "Integer".equals(attrType) || "BigDecimal".equals(attrType) || "Long".equals(attrType) || "Short".equals(attrType) || "Float".equals(attrType) || "Double".equals(attrType);
	}

	public void setNumber(boolean number) {
		isNumber = number;
	}

	public Long getMaxValue() {
		return maxValue;
	}

	public String getMaxValueString() {
		if (null == maxValue) {
			if ("Short".equals(attrType)) {
				return "Short.MAX_VALUE";
			}
			if ("Long".equals(attrType)) {
				return "Long.MAX_VALUE";
			}
			if ("Integer".equals(attrType)) {
				return "Integer.MAX_VALUE";
			}
			return "0";
		}
		if (maxValue == Integer.MAX_VALUE) {
			return "Integer.MAX_VALUE";
		}
		if (maxValue == Long.MAX_VALUE) {
			return "Long.MAX_VALUE";
		}
		if (maxValue > Integer.MAX_VALUE) {
			return maxValue + "L";
		}
		return maxValue + "";
	}

	public void setMaxValue(Long maxValue) {
		this.maxValue = maxValue;
	}

	public Boolean getIsGmtField() {
		String attrName = this.attrname;
		return ("creatorId".equals(attrName) || "creatorName".equals(attrName) || "createTime".equals(attrName)
				|| "updaterId".equals(attrName) || "updaterName".equals(attrName) || "updateTime".equals(attrName)
				|| "tenantId".equals(attrName));
	}
}
